package com.yami.shop.mystery.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.User;
import com.yami.shop.mystery.common.dao.UserInviteMapper;
import com.yami.shop.mystery.common.dto.UserInviteDto;
import com.yami.shop.mystery.common.model.UserInvite;
import com.yami.shop.mystery.common.service.UserInviteService;
import com.yami.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInvite> implements UserInviteService {

    @Autowired
    private UserService userService;

    @Override
    public List<Map<String, Object>> getTops(Long activityId) {
        // 获取拉新前10 人
        List<UserInviteDto> userInviteDtos = this.baseMapper.getTops(activityId);
        ArrayList<Map<String, Object>> tops = new ArrayList<>();
        for(UserInviteDto userInviteDto : userInviteDtos){
            HashMap<String, Object> topMap = new HashMap<>();
            topMap.put("num",userInviteDto.getInviteNum());
            // 获取用户名称
            User userDetail = userService.getUserDetail(userInviteDto.getUserId());
            topMap.put("name",userDetail.getRealName());
            tops.add(topMap);
        }
        return tops;
    }

    @Override
    public List<UserInviteDto> selectConformToRules(Long activityId, String ruleType, Long conditionNum, Long isReal) {
        return this.baseMapper.selectConformToRules(activityId,ruleType,conditionNum,isReal);
    }

}
